package com.woniuxy.springparking.controller;

import com.woniuxy.springparking.asepct.SysLog;
import com.woniuxy.springparking.common.RestDto;
import com.woniuxy.springparking.common.RestResult;
import com.woniuxy.springparking.service.LogService;
import com.woniuxy.springparking.vo.LogVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class LogController {

    @Autowired
    private LogService logService;

    //查询日志
    @GetMapping(value = "/logSelectByPage.do")
    @ApiOperation(value = "分页查询所有日志信息",httpMethod = "GET",
                 protocols = "HTTP",produces = "application/json",
                  response = RestResult.class,notes = "分页查询所有日志信息")
    public RestResult list(LogVO vo) {
        return logService.findByPage(vo);
    }

    //插入日志
//    @PostMapping("/createLog")
//    public RestResult create(Log log){
//
//       logService.saveLog(log);
//        return RestResult.ok("添加成功");
//    }

    //删除日志
    @DeleteMapping("/deleteLog.do")
    @ApiOperation(value = "按id删除日志信息",httpMethod = "DELETE",
            protocols = "HTTP",produces = "application/json",
            response = RestDto.class,notes = "按id删除日志信息")
    @SysLog(value1 = "删除",value2 = "删除日志")
    public RestDto deleteLog(Integer id) {
        RestDto dto = new RestDto();
        try {
            this.logService.removeLog(id);
            dto.setCode(200);
            dto.setMsg("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            dto.setCode(-1);
            dto.setMsg("删除成功");
        }
       return dto;
    }

   //批量删除
    @DeleteMapping("/deleteManyLog.do")
    @ApiOperation(value = "批量删除日志信息",httpMethod = "DELETE",
            protocols = "HTTP",produces = "application/json",
            response = RestDto.class,notes = "批量删除日志信息")
    @SysLog(value1 = "删除",value2 = "批量删除日志")
    public RestDto deleteManyLog(@RequestParam("ids[]") Integer[] ids) {
        RestDto dto = new RestDto();
        try {
            this.logService.removeManyLog(ids);
            dto.setCode(200);
            dto.setMsg("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            dto.setCode(-1);
            dto.setMsg("删除成功");
        }
        return dto;
    }

}
